<?php
class ServiceOrderRowRepairesController extends AppController {
	public $helpers = array('Html', 'Form', 'Session');
	public $components = array('Session');
	public $uses = array('ServiceOrderRowRepaire','ServiceOrderRow', 'Repaire');

//service_order_row_states
	public function index() {
		$this->set('service_order_rows', $this->ServiceOrderRowRepaire->find('all'));
	}

	public function ver() {
	// últimos posts (para el elemento latest_posts)
  // Si la petición fue realizada por medio de requestAction
    if(isset($this->params['requested'])) { 
      return $this->ServiceOrderRowRepaire->find('all');
		}
	}
  

	public function add($id = null) {	
		$this->set('service_order_row_id', $id);
		$this->set('default_date',date ('Y-m-d H:i:s'));
		$this->set('service_order_row_repaires', $this->Repaire->find('list', array('fields' => array('id', 'descripcion'),'order' => array('Repaire.descripcion ASC') )));
		if ($this->request->is('post')) {
			$this->ServiceOrderRowRepaire->create();
			if ($this->ServiceOrderRowRepaire->save($this->request->data)) {
				$this->Session->setFlash('Se han guardado los cambios.');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('No se pudieron guardar los cambios.');
			}
		}
	}
	
	function delete($id) {
    if (!$this->request->is('service_order_row_repaires')) {
        throw new MethodNotAllowedException();
    }
    if ($this->Post->delete($id)) {
        $this->Session->setFlash('La reparacion: ' . $id . ' sera borrada.');
        $this->redirect(array('action' => 'index'));
    }
}
	public function edit($id = null) {
    	$this->ServiceOrderRowRepaire->id = $id;
    	if ($this->request->is('get')) {
    		//Agregado
    		$this->set('default_date',date ('Y-m-d H:i:s'));
    		$service_order_row_id = $this->ServiceOrderRowRepaire->service_order_row_id;
    		//$this->set('service_order_row_id', $this->ServiceOrderRowRepaire->service_order_row_id);
    		$this->set('service_order_row_repaires', $this->Repaire->find('list', array('fields' => array('id', 'descripcion'),'order' => array('Repaire.descripcion ASC') )));
    		//Fin agregado
    		$this->request->data = $this->ServiceOrderRowRepaire->read();

    	} else {
    		if ($this->ServiceOrderRowRepaire->save($this->request->data)) {
    			$this->Session->setFlash('Datos actualizados correctamente.');
    			$service_order_row_id = $this->data['ServiceOrderRowRepaire']['service_order_row_id'];
    			$this->redirect(array('controller' => 'ServiceOrderRows', 'action' => 'embandado', $service_order_row_id));
    		} else {
    			$this->Session->setFlash('No se pudieron guardar los cambios.');
    		}
    	}
    }

}